Ext.define('PJ.view.attendancemanagement.SeeparticipatingList', {
    extend: 'AM.default.DefaultList',
	alias: 'widget.seeparticipatingList',
	
    initComponent: function(){
    	var me = this;
        this.columns = [{
            header: '参训状态',
            dataIndex: 'userState',
            width: 125,
            //sortable: false,
            renderer: function(v, meta, record){
            	if(v == 1){
            		return "参训";
            	}else if(v == 2){
            		return "未参训";
            	}
            }
        },{
        	header: '学员帐号',
        	dataIndex: 't.user.loginID',
        	width: 110
        },{
        	header: '姓名',
        	dataIndex: 't.userName',
        	width: 80
        }, {
            header: '性别',
            dataIndex: 't.sexCode',
            width: 45
        },{
            header: '年龄',
            dataIndex: 't.birthday',
            width: 45,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '民族',
            dataIndex: 't.folkCode',
            width: 80,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '单位及职务',
            dataIndex: 't.dutyRemark',
            width: 100,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '联系电话',
            dataIndex: 't.mobileTelephone',
            width: 100,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '备注',
            dataIndex: 't.remark',
            flex:1,
            minWidth: 120,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }];
        this.store = Ext.create('PJ.'+prototype+'.attendancemanagement.SeeparticipatingList', {
            isLoad: false
        });
        this.loadType = gj_onlineLearning_constant.loadType;
        this.callParent(arguments);
    },
    /**
     * 参训
     */
    onParticipatingClick: function(button){
    	  var me = this;
      	  var store = me.getStore();
      	  var records = me.getSelectionModel().getSelection();
          var form = button.up('form');
          //var gridPanel = form.grid;
      	Ext.Msg.confirm({
    		  title:'提示',
    		  msg:'您确定要设置这些学员已参训吗?',
    		  icon:Ext.Msg.WARNING,
    		  buttons:Ext.Msg.OKCANCEL,
    		  fn:function(id){
    			  if(id=='ok'){
    				  var userIds= new Array();
    				  Ext.Array.each(records,function(name,index){
    					  userIds.push(name.get('userId'));
    				  });
    				  if(gj_onlineLearning_constant.loadType == "jsonp"){
    					  var store1 = Ext.create('AM.default.jsonp.DefaultAjaxStore',{
                      		loadType: gj_onlineLearning_constant.loadType,
                              url: store.participatingUrl,
                      		  extraParams: {
                      			searchUserIds: userIds,
    		                  	searchClassID:me.up('window').classId,
    		                  	SearchUserState:1
                              }
                      	});
                      	store1.load(function(rec, operation, success){
                      		if(success){
                                  Ext.Msg.alert('消息', '设置参训成功！', function(){
                                      var store = me.getStore();
                                      store.load();
                                  });
                              }else{
                                  Ext.Msg.alert('消息', operation.error);
                              }
                      	});
    				  }else{
    					  Ext.Ajax.request({
    						  url:store.participatingUrl,
    						  params: {
    							searchUserIds: userIds,
    		                  	searchClassID:me.up('window').classId,
    		                  	SearchUserState:1
    	                       },
    						  success:function(response){
    							  var data=response.responseText;
    							  var json=Ext.decode(data,true);
    							  if(json.success){
    								  Orchid.alert('提示','设置参训成功!',function(){
    									  store.load();
    								  });
    							  }else{
    								  Orchid.alert('提示',json.msg);
    							  }
    						  }
    					  });
    				  }
    			  }
    		  }
    	  });
    	},
    /**
     * 未参训
     */
    onUNParticipatingClick: function(button){
  	  var me = this;
  	  var store = me.getStore();
  	  var records = me.getSelectionModel().getSelection();
      var form = button.up('form');
  	Ext.Msg.confirm({
		  title:'提示',
		  msg:'您确定要设置这些学员未参训吗?',
		  icon:Ext.Msg.WARNING,
		  buttons:Ext.Msg.OKCANCEL,
		  fn:function(id){
			  if(id=='ok'){
				  var userIds= new Array();
				  Ext.Array.each(records,function(name,index){
					  userIds.push(name.get('userId'));
				  });
				  if(gj_onlineLearning_constant.loadType == "jsonp"){
					  var store1 = Ext.create('AM.default.jsonp.DefaultAjaxStore',{
                  		loadType: gj_onlineLearning_constant.loadType,
                          url: store.unParticipatingUrl,
                  		  extraParams: {
                  			searchUserIds: userIds,
                  			searchClassID:me.up('window').classId,
		                  	SearchUserState:2
                          }
                  	});
                  	store1.load(function(rec, operation, success){
                  		if(success){
                              Ext.Msg.alert('消息', '设置未参训成功！', function(){
                                  var store = me.getStore();
                                  store.load();
                              });
                          }else{
                              Ext.Msg.alert('消息', operation.error);
                          }
                  	});
				  }else{
					  Ext.Ajax.request({
						  url:store.unParticipatingUrl,
						  params: {
							 searchUserIds: userIds,
	                  		searchClassID:me.up('window').classId,
		                  	SearchUserState:2
	                       },
						  success:function(response){
							  var data=response.responseText;
							  var json=Ext.decode(data,true);
							  if(json.success){
								  Orchid.alert('提示','设置未参训成功!',function(){
									  store.load();
								  });
							  }else{
								  Orchid.alert('提示',json.msg);
							  }
						  }
					  });
				  }
			  }
		  }
	  });
	},
    listeners: {
    	selectionchange: function(selModel, selected){
    		this.down('#' + this.oldId + 'Participating').setDisabled(selected.length === 0);
    		this.down('#' + this.oldId + 'UNParticipating').setDisabled(selected.length === 0);
    	},
    	viewready: function(){
    		this.addDocked([{
                dock: 'top',
                xtype: "searchform",
    			columnCount: 2,
    			collapsedFieldSet: false,
                fieldDefaults: {
                    xtype: "textfield",
                    labelAlign: 'right',
                    labelWidth: 80
                },
                items: [{
                    fieldLabel: '学员帐号',
                    name: "searchLoginID",
                    emptyText: "请输入学员帐号",
                    maxLength: 50
                }, {
                    fieldLabel: "姓名",
                    name: "searchUserName",
                    emptyText: "请输入姓名",
                    maxLength: 100
                }],
    			onResetClick: function(button){
                    var form = button.up('form');
                    var gridPanel = form.grid;
                    var newParams = {
            				searchClassID: gridPanel.up('window').classId
                    };
                    gridPanel.getStore().proxy.extraParams = {};
                    var params = gridPanel.getStore().proxy.extraParams;
                    Ext.apply(params, newParams);
                    form.getForm().reset();
                },
                grid: this
            },{
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [{
                    text: '参训',
                    iconCls: 'participateIco',
                    itemId: this.oldId + "Participating",
                    disabled: true,
                    scope: this,
                    handler: this.onParticipatingClick
                }, '-', {
                    text: '未参训',
                    iconCls: 'didNotParticipateIco',
                    itemId: this.oldId + "UNParticipating",
                    disabled: true,
                    scope: this,
                    handler: this.onUNParticipatingClick
                }]
            }]);
    		// 触发权限过滤事件
    		this.fireEvent("permission", this);
    		var params = this.store.proxy.extraParams;
    		var newParams = {
    				searchClassID: this.up('window').classId
    		};
    		Ext.apply(params, newParams);
    		this.store.isLoad = true;
    		this.store.load();
    		//this.quotaOfPeople();//单位授人数统计
    	}
    }
});
